package org.opens.controller;

import io.swagger.annotations.*;
import org.opens.entity.User;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/api/user")
@Api(value = "用户信息查询", description = "用户基本信息操作API", tags = "UserApi")
public class UserController {

    @ApiOperation(value = "/getUser", notes = "根据姓名查询用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "姓名", required = true, paramType = "query"),
            @ApiImplicitParam(name = "sex", value = "性别", required = true, paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "请求成功"),
            @ApiResponse(code = 400, message = "请求参数没填好"),
            @ApiResponse(code = 404, message = "请求路径没有或页面跳转路径不对"),
            @ApiResponse(code = 500, message = "服务器异常"),
    })
    @RequestMapping(value = "/getUser", method = RequestMethod.GET)
    @ResponseBody
    public User getUser(@RequestParam("name") String name, @RequestParam(value = "sex") String sex) {
        User user = new User();
        user.setId(123456);
        user.setName(name);
        user.setAge(25);
        user.setAddress("河南郑州");
        user.setSex(sex);
        return user;
    }

    @ApiOperation(value = "/addUser", notes = "添加一个用户")
    @ApiResponses({
            @ApiResponse(code = 200, message = "请求成功"),
            @ApiResponse(code = 400, message = "请求参数没填好"),
            @ApiResponse(code = 404, message = "请求路径没有或页面跳转路径不对"),
            @ApiResponse(code = 500, message = "服务器异常"),
    })
    @RequestMapping(value = "/addUser", method = RequestMethod.POST)
    @ResponseBody
    public User addUser(@RequestBody User user) {
        return user;
    }

}
